package gui.specialGUIs;

import gui.designComponents.TMTPanel;
import gui.designComponents.TMTTitledBorder;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.util.ResourceBundle;

import app.Controller;
import app.Model;
import bundles.BundleLoader;
import definitions.Commands;

/**
 * Start Page of this application
 * 
 * @author MK
 * 
 */
public class StartView extends TMTPanel {

	private NearAppointmentsPanel nearAppointmentsPanel;
	private RosterStatesOverview rosterStatesPanel;

	private Model model;
	private Controller controller;

	public StartView(Model model, Controller controller) {

		this.model = model;
		this.controller = controller;

		setLayout(new GridLayout(2, 1));

		nearAppointmentsPanel = new NearAppointmentsPanel(model, controller);
		rosterStatesPanel = new RosterStatesOverview(model, controller);

		add(nearAppointmentsPanel);
		add(rosterStatesPanel);
	}

	public void update() {

		remove(nearAppointmentsPanel);
		remove(rosterStatesPanel);
		this.nearAppointmentsPanel = new NearAppointmentsPanel(model,
				controller);
		this.rosterStatesPanel = new RosterStatesOverview(model, controller);
		add(nearAppointmentsPanel);
		add(rosterStatesPanel);
	}
}

class NearAppointmentsPanel extends TMTPanel {

	private TablePanel nearAppointments;

	public NearAppointmentsPanel(Model model, Controller controller) {

		setLayout(new BorderLayout());

		ResourceBundle resBundle = BundleLoader.getResourceBundle();

		nearAppointments = new TablePanel(model, controller,
				Commands.SHOW_EVENT_OVERVIEW_NEAR);

		nearAppointments.setBorder(new TMTTitledBorder(resBundle
				.getString("nearAppointments")));

		add(nearAppointments, BorderLayout.CENTER);
	}
}

class RosterStatesOverview extends TMTPanel {

	private TablePanel healthyPlayersPanel;
	private TablePanel notHealthyPlayersPanel;

	public RosterStatesOverview(Model model, Controller controller) {

		setLayout(new GridLayout(1, 2));

		ResourceBundle resBundle = BundleLoader.getResourceBundle();

		healthyPlayersPanel = new TablePanel(model, controller,
				Commands.SHOW_MEMBER_OVERVIEW_HEALTHY);

		notHealthyPlayersPanel = new TablePanel(model, controller,
				Commands.SHOW_MEMBER_OVERVIEW_NOT_HEALTHY);

		healthyPlayersPanel.setBorder(new TMTTitledBorder(resBundle
				.getString("healthyPlayers")));
		notHealthyPlayersPanel.setBorder(new TMTTitledBorder(resBundle
				.getString("notHealthyPlayers")));

		add(healthyPlayersPanel);
		add(notHealthyPlayersPanel);
	}
}